package com.leyou.trade.dto;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.leyou.common.dto.BaseDTO;
import com.leyou.common.entity.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

@EqualsAndHashCode(callSuper = true)
@Data
public class OrderWithDetailDTO extends BaseDTO {

    @JsonSerialize(using= ToStringSerializer.class)
    private Long orderId;
    private Long totalFee;
    private Long postFee;
    private Integer status;
    private Long actualFee;
    private Date createTime;
    private Date payTime;
    private Date consignTime;
    private Date endTime;
    private Date closeTime;
    private Date commentTime;

    private List<OrderDetailDTO> orderDetails;

    public OrderWithDetailDTO( BaseEntity entity) {
        super(entity);
    }


    /**
     * 将PO集合转为DTO集合
     * @param list PO对象的集合
     * @param <T> PO的类型
     * @return DTO集合
     */
    public static <T extends BaseEntity> List<OrderWithDetailDTO> convertEntityList( Collection<T> list){
        if(list == null || list.size() == 0){
            return Collections.emptyList();
        }
        return list.stream().map(OrderWithDetailDTO::new).collect(Collectors.toList());
    }


}